//
//  SZCTabBarController.m
//  礼物说
//
//  Created by dllo on 16/4/19.
//  Copyright © 2016年 sunzhichao. All rights reserved.
//

#import "SZCTabBarController.h"

@interface SZCTabBarController ()

@end

@implementation SZCTabBarController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.viewControllers = [self createRootOfVCs];
    }
    return self;
}

-(void)dealloc{
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"night" object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"day" object:nil];
    [super dealloc];
}


#pragma mark - TabBar
- (NSArray<UIViewController *> *)createRootOfVCs {
    NSMutableArray *arrOfVCs = [NSMutableArray array];
    
    /** Gift*/
    SZCGiftViewController *GiftVC = [[SZCGiftViewController alloc] init];
    SZCNavigationController *GiftNav = [[SZCNavigationController alloc] initWithRootViewController:GiftVC];
    [arrOfVCs addObject:GiftNav];
    [GiftNav release];
    [GiftVC release];
    UIImage *GiftImage = [[UIImage imageNamed:@"gift_32px_1076845_easyicon.net"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *giftImage = [[UIImage imageNamed:@"gift_open_32px_1076846_easyicon.net"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    GiftNav.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"嗨购" image:GiftImage selectedImage:giftImage] autorelease];
    
    /** Hot*/
    SZCHotViewController *HotVC = [[SZCHotViewController alloc] init];
    SZCNavigationController *HotNav = [[SZCNavigationController alloc] initWithRootViewController:HotVC];
    [arrOfVCs addObject:HotNav];
    [HotNav release];
    [HotVC release];
    UIImage *HotImage = [[UIImage imageNamed:@"shopping_basket_32px_1187399_easyicon.net"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *hotImage = [[UIImage imageNamed:@"shopping_basket_full_32px_1187402_easyicon.net"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    HotNav.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"热门" image:HotImage selectedImage:hotImage] autorelease];
    
    /** 分类*/
    SZCClassificationViewController *ClassVC = [[SZCClassificationViewController alloc] init];
    SZCNavigationController *ClassNav = [[SZCNavigationController alloc] initWithRootViewController:ClassVC];
    [arrOfVCs addObject:ClassNav];
    [ClassNav release];
    [ClassVC release];
    UIImage *ClassImage = [[UIImage imageNamed:@"search_file_32px_1187344_easyicon.net"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *classImage = [[UIImage imageNamed:@"Open_folder_search_32px_1186196_easyicon.net"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    ClassNav.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"分类" image:ClassImage selectedImage:classImage] autorelease];
    
    /** 我*/
    SZCMinesViewController *MinesVC = [[SZCMinesViewController alloc] init];
    SZCNavigationController *MinesNav = [[SZCNavigationController alloc] initWithRootViewController:MinesVC];
    [arrOfVCs addObject:MinesNav];
    [MinesNav release];
    [MinesVC release];
    UIImage *MinesImage = [[UIImage imageNamed:@"people_outline_32px_1182103_easyicon.net"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *minesImage = [[UIImage imageNamed:@"people_32px_1182102_easyicon.net"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    MinesNav.tabBarItem = [[[UITabBarItem alloc] initWithTitle:@"我" image:MinesImage selectedImage:minesImage] autorelease];
    
    return arrOfVCs;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.tabBar.translucent = NO;
    BOOL result = [[NSUserDefaults standardUserDefaults] boolForKey:@"isNight"];
    
    if (result == YES) {
        /**夜间 */
        self.tabBar.barTintColor = [UIColor colorWithWhite:0.200 alpha:1.000];
        self.tabBar.tintColor = [UIColor whiteColor];
        
    }else{
        
        /**白天 */
        
        self.tabBar.barTintColor = [UIColor whiteColor];
        self.tabBar.tintColor = [UIColor grayColor];
    }
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(nightAction:) name:@"night" object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dayAction:) name:@"day" object:nil];
    
    
    
}
- (void)nightAction:(NSNotification *)notification {
    
    
    
    NSLog(@"夜间模式开始成功");
    self.tabBar.barTintColor = [UIColor colorWithWhite:0.200 alpha:1.000];
    self.tabBar.tintColor = [UIColor whiteColor];
    
    
    
}

- (void)dayAction:(NSNotification *)notification {
    
    NSLog(@"日间模式开启成功");
    
    self.tabBar.barTintColor = [UIColor whiteColor];
    self.tabBar.tintColor = [UIColor grayColor];
}

    
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
